
<html>

<head>
    <include file="public@head" title="注册用户-用户列表"/>
</head>

<body class="layui-layout-admin">
<include file="public@header"/>
<include file="public@side"/>
<div class="layui-body">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a href="{:url('tdadmin/index/index')}">主页</a>
        <a href="{:url('tdadmin/database/index')}">数据库管理</a>
        <a><cite>数据库管理</cite></a>
    </div>
    <div class="layui-fluid pdt10">
        <div class="layui-card">
            <div class="layui-card-header">
                数据库管理
            </div>
            <div class="layui-card-body">
                <div class="listsTable layui-form">

                </div>

                <table class="layui-hide table-center" id="lists" lay-filter="lists"></table>

                <script type="text/html" id="imgTpl">
                    <img src="{{d.avatar}}" height="42">
                </script>

                <script type="text/html" id="barLists">
                    <a class="layui-btn  layui-btn-sm" lay-event="download"><i class="layui-icon layui-icon-list"></i>下载</a>
                    <a class="layui-btn  layui-btn-sm" lay-event="restore"><i class="layui-icon layui-icon-list"></i>恢复</a>
                    <a class="layui-btn layui-btn-danger  layui-btn-sm" lay-event="delete"><i class="layui-icon layui-icon-list"></i>删除</a>
                </script>
            </div>
        </div>
    </div>
</div>
<include file="public@scripts"/>
<script>
    var table = layui.table;
    table.render({
        elem: '#lists',
        even: true,
        id: 'listsReload',
        url: "{:url('getFileList')}",
        cols: [[
              {title: '时间', align: 'center', width: 250, templet:function (data) {
                      console.log(data);
                      var keys = Object.keys(data)
                      return data.LAY_TABLE_INDEX;
                  }}
            , {field: 'size', title: '大小/kb', width: 180}
            , {field: 'LAY_TABLE_INDEX', title: '备份时间', width: 250}
		    , { fixed: 'right', title: '操作', align: 'center',width:250, toolbar: '#barLists' }
        ]],
        page: false
    });

    $('.listsTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(lists)', function(obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'download') {
            layer.confirm('下载【' + data.LAY_TABLE_INDEX + '】表？', function(index) {
                layer.close(index);
                window.location.href = "{:url('download')}?time="+data.time;
            });
        }
        if(layEvent === 'restore') {
            layer.confirm('恢复该时间的备份？', function(index) {
                layer.close(index);
                $.post("{:url('restore')}",{time:data.time},function (res) {
                    layer.msg(res.msg, {}, function() {
                        if(res.url) { //如果返回值有需要跳转的url则跳转，否则重载当前页面
                            window.location.href = res.url;
                        } else {
                            window.location.reload();
                        }
                    });
                })
            });
        }

        if(layEvent === 'delete') {
            layer.confirm('删除备份？', function(index) {
                layer.close(index);
                $.post("{:url('delete')}",{time:data.time},function (res) {
                    layer.msg(res.msg, {}, function() {
                        if(res.url) { //如果返回值有需要跳转的url则跳转，否则重载当前页面
                            window.location.href = res.url;
                        } else {
                            window.location.reload();
                        }
                    });
                })
            });
        }
    });

</script>
</body>

</html>
